package com.kaifamiao.month03.day0321;

public class QuickSort1 {

    public static void main(String[] args) {
        int[] nums = {1, 2, 56, 52, 54, 23, 0};
        quickSort(nums, 0, nums.length - 1);
        print(nums);
    }

    public static int getMid(int[] nums, int low, int high){
        int temp = nums[low];
        while(low < high){
            while(nums[high] >= temp && low < high){
                high --;
            }
            nums[low] = nums[high];
            while(nums[low] <= temp && low < high){
                low ++;
            }
            nums[high] = nums[low];
        }
        nums[low] = temp;
        return low;
    }

    public static void quickSort(int[] nums , int low , int high){
        if(low < high){
            int mid = getMid(nums,low,high);
            quickSort(nums, low, mid - 1);
            quickSort(nums, mid + 1, high);
        }
    }

    public static void print(int[] nums){
        for (int n : nums) {
            System.out.print(n + "\t");
        }
    }
}
